package com.rhok.wthru_client.servermsgs;

import org.apache.http.HttpResponse;
import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

import com.google.android.maps.GeoPoint;
import com.rhok.wthru_client.BasicContactInfo;

public class ServerMessageRequestLocation extends ServerMessageWithSelfInfo {
	
	private BasicContactInfo [] m_contacts;
	private GeoPoint m_myLocation;
	
	public ServerMessageRequestLocation(Context context) {
		super(context);
		
		m_contacts = null;
		m_myLocation = null;
	}
	
	public void setMyLocation(GeoPoint myLocation) {
		m_myLocation = myLocation;
	}
	
	public void setContacts(BasicContactInfo [] contacts) {
		m_contacts = contacts;
	}
	
	public String send() {
		int index = 0;
		for(BasicContactInfo contact : m_contacts) {
			m_requestValues.add(new BasicNameValuePair("contact_info[" + index + "]", contact.toString()));
			++index;
		}
		m_requestValues.add(new BasicNameValuePair("contacts_count", Integer.valueOf(index).toString()));
		if (m_myLocation != null)
			m_requestValues.add(new BasicNameValuePair("my_location", m_myLocation.toString()));
		HttpResponse response = super.sendPostRequest();
		return getResponseString(response);
	}

	@Override
	protected String getRequestPath() {
		return "request_location";
	}

}
